<%-- 
    Document   : manage
    Created on : Sep 21, 2011, 8:20:36 PM
    Author     : SAMMY
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="/header.jsp"></jsp:include>
    <script type="text/javascript">
        $(document).ready(function() {
            $('a.delete').click(function(e) {
                e.preventDefault();
            
                var answer = confirm("Do you want to delete this payment?");
            
                if (answer){
                    var parent = $(this).parent().parent();
            
                    $.ajax({
                        type: 'get',
                        url: 'payments',
                        data: 'action=delete&id=' + parent.attr('id').replace('record-', ''),
                        beforeSend: function() {
                            parent.fadeTo('slow', 0.25);
                        },
                        success: function() {
                            parent.find('td').wrapInner('<div style="display: block;" />').parent().find('td > div').slideUp(300, function() {
                                parent.remove();
                            });
                        },
                        error: function() {
                            parent.stop().fadeTo('slow', 1);
                        }
                    });
                }
            });
            
            $('a.approve').click(function(e) {
                e.preventDefault();
            
                var answer = confirm("Do you want to approve this payment?");
            
                if (answer){
                    var parent = $(this).parent().parent();
            
                    $.ajax({
                        type: 'get',
                        url: 'payments',
                        data: 'action=approve&id=' + parent.attr('id').replace('record-', ''),
                        beforeSend: function() {
                            parent.fadeTo('slow', 0.25);
                        },
                        success: function() {
                            parent.remove();
                        },
                        error: function() {
                            parent.stop().fadeTo('slow', 1);
                        }
                    });
                }
            });
        });
    </script>
    <h1>Manage Payments</h1>
    <table>
        <tr>
            <th></th>
            <th>Bill Number</th>
            <th>Booking Code</th>
            <th>Status</th>
            <th>Action</th>
        </tr>
    <c:set var="ordinal" value="${0}" />
    <c:forEach items="${payments}" var="payment">
        <c:set var="ordinal" value="${ordinal + 1}" />
        <tr id="record-${payment.id}">
            <td>${ordinal}</td>
            <td>${payment.billno}</td>
            <td>${payment.bookingCode}</td>
            <td><c:choose><c:when test="${payment.status == '0'}">NOT CONFIRMED</c:when><c:when test="${payment.status == '1'}">CONFIRMED</c:when></c:choose></td>
            <td><a class="approve" href="./payments?action=approve&id=${payment.id}">Approve</a> <a class="delete" href="./payments?action=delete&id=${payment.id}">Delete</a></td>
        </tr>
    </c:forEach>
</table>
<jsp:include page="/footer.jsp"></jsp:include>